class ContentsController < ApplicationController

  def show
    content = find_content
    if content.is_a_page?
      @content_body = content.as_a_page.body
      render :partial => "page", :layout => @layout
    elsif content.is_a_document_category?
      @document_category = content.as_a_document_category
      @content_body = @document_category.description
      render :partial => "documents", :layout => @layout
    elsif content.is_a_gallery?
      @gallery = content.as_a_gallery
      render :partial => "gallery", :layout => @layout
    elsif content.is_a_picture?
      @artwork = content.as_a_picture
      render :partial => "artwork", :layout => @layout
    end
  end

  private 

  def find_content
    content = Content.find_by_url(params[:p1], :include => :user_groups)
    unless content_allowed?(content, current_user_user_group_ids)
      raise SecurityError, "Access to resource not allowed"
    end
    content
  end
end
